
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.wlcorp.forcazamis.sys.util.AppConstant" %>
<%@ page import="com.wlcorp.forcazamis.sys.util.CommonUtil" %>
<%@ page import="java.util.List" %>
<%@ page import="com.wlcorp.forcazamis.domain.pi.PiproductDetail" %>
<%@ page import="com.wlcorp.forcazamis.domain.pi.Pidetail" %>
<%@ page import="com.wlcorp.forcazamis.domain.sample.SubSample" %>

<%
	Pidetail pidetail = (Pidetail)request.getAttribute("pidetail");
	List piproductList = (List)request.getAttribute("piproductList");
%>
<html>
<head>
	<title>合同产品信息</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Expires" content="0">
	<link href="${pageContext.request.contextPath}/css/css.css" rel=stylesheet>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/button_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/form_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/table_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagetitle_css.css" type="text/css">
	<script language="javascript" src="${pageContext.request.contextPath}/script/validator.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/calendartime.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/ajax.js"></script>
	<script type="text/javascript">
		function doSave(){
			//var inputArray = document.forms["piproduct"].getElementsByTagName("input");
			//for(i = 0;i < inputArray.length;i++){
				//if("prodCount" == inputArray[i].name && "text" == inputArray[i].type && inputArray[i].value.length > 0 && parseInt(inputArray[i].value) <= 0){
				//	alert("数量必须大于0！");
				//	return;
				//}
				//if("price" == inputArray[i].name && "text" == inputArray[i].type && inputArray[i].value.length > 0 && parseInt(inputArray[i].value) <= 0){
				//	alert("单价必须大于0！");
				//	return;
				//}
			//}
			document.forms["piproduct"].submit();
		}
		function baseInfoEdit(piid){
			window.location = "${pageContext.request.contextPath}/pi/pidetailManager.do?method=getPidetail&piid=" + piid;
		}
		
		function addNewPiproduct(){
			var returnValue = window.showModalDialog("${pageContext.request.contextPath}/storagein/storageInManager.do?method=selectSubSampleListTop"
				,window,"dialogHeight:400px;dialogWidth:580px;center:yes;help:no;resizable:no;status:no;");
			
			if(returnValue && null != returnValue){
				var table = document.getElementById("piproductTbody");
				for(i = 0;i < returnValue.length;i++){
					appendRow(table,returnValue[i],'<%=AppConstant.PI_PRODUCT_IS_NEW%>');
				}
			}
		}
		
		function deleteRow(tr){
			if(confirm("确定删除？")){
				var table = document.getElementById("piproductTbody");
				table.removeChild(tr);
			}
		}
		
		function appendRow(table,subSample,isNew){
		  
          var tr = document.createElement('<tr id="' + subSample["subSampleId"] + '" bgcolor="#ffffff">');
          var td = document.createElement('<td width="10%">');
          td.innerHTML = "";
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input type="hidden" name="productId" value=""/><input type="hidden" name="subSampleId" value="' + subSample["subSampleId"] + '"/>'
          	+ '<input type="hidden" name="isNew" value="' + isNew + '"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = ' ';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="custProdCode" value="" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = subSample["sampleCode"];
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="color" value="' + subSample["ccolorDesc"] + '" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="prodCount" value="0" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + subSample["subSampleId"] + '\'))" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="price" value="0.00" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + subSample["subSampleId"] + '\'))" style="width:60px"/>'
          	+ '<input class="input" type="text" name="priceAdd" value="0.0" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + subSample["subSampleId"] + '\'))" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="totalSum" value="0.00" maxlength="10" readOnly style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="type" value="" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="remark" value="" maxlength="100" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="orderNo" value="1" maxlength="10" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="pageNo" value="1" maxlength="10" style="width:60px"/>';
          tr.appendChild(td);
          
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="ecolor" value="' + subSample["ecolorDesc"] + '" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="size" value="' + subSample["size"] + '" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="col" value="' + subSample["plateColor"] + '" maxlength="20" style="width:60px"/>';
          
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<a href="javascript:deleteRow(document.getElementById(\'' + subSample["subSampleId"] + '\'))">删除</a>';
          tr.appendChild(td);
          table.insertBefore(tr,table.rows[table.rows.length - 1]);
        }
        
        function getTotalPrice(tr){
        	var totalPriceTxt = tr.cells[8].getElementsByTagName("input")[0];
        	//alert("totalPriceTxt="+totalPriceTxt.name+totalPriceTxt.value);
        	var priceTxt = tr.cells[7].getElementsByTagName("input")[0];
        	var priceAddTxt = tr.cells[7].getElementsByTagName("input")[1];
        	var count = tr.cells[6].getElementsByTagName("input")[0];
        	totalPriceTxt.value = (parseFloat(priceTxt.value) + parseFloat(priceAddTxt.value)) * parseFloat(count.value);
        }
        
        function doSubmitConfirm(){
        	
			var sUrl = "${pageContext.request.contextPath}/confirm/confirmManager.do?method=submitConfirm"
				+ "&confirmType=<%=AppConstant.CONFIRM_TYPE_IN_STORAGE%>&itemId=${storageIn.storageInId}";
			ajaxRead(sUrl,function(obj){
				var result = obj.responseText;
				alert(result);
				document.getElementById("submitConfirmBtn").disabled = true;
			});
		}
		
		function selectNewPiproduct(customerId){
			var returnValue = window.showModalDialog("${pageContext.request.contextPath}/pi/pidetailManager.do?method=selectPiProductTop&customerId=" + customerId
				,window,"dialogHeight:400px;dialogWidth:680px;center:yes;help:no;resizable:no;status:no;");
			
			if(returnValue && null != returnValue){
				var table = document.getElementById("piproductTbody");
				for(i = 0;i < returnValue.length;i++){
					appendRowRe(table,returnValue[i],'<%=AppConstant.PI_PRODUCT_IS_OLD%>');
				}
			}
		}
		
		function appendRowRe(table,piproduct,isNew){
		  
          var tr = document.createElement('<tr id="' + piproduct["subSampleId"] + '" bgcolor="#ffffff">');
          var td = document.createElement('<td width="10%">');
          td.innerHTML = "";
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input type="hidden" name="productId" value=""/><input type="hidden" name="subSampleId" value="' + piproduct["subSampleId"] + '"/>'
          	+ '<input type="hidden" name="isNew" value="' + isNew + '"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = ' ';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="custProdCode" value="' + piproduct["custProdCode"] + '" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = piproduct["sampleCode"];
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="color" value="' + piproduct["color"] + '" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="prodCount" value="' + piproduct["prodCount"] + '" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + piproduct["subSampleId"] + '\'))" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="price" value="' + piproduct["price"] + '" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + piproduct["subSampleId"] + '\'))" style="width:60px"/>'
          	+ '<input class="input" type="text" name="priceAdd" value="' + piproduct["priceAdd"] + '" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + piproduct["subSampleId"] + '\'))" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="totalSum" value="' + piproduct["totalSum"] + '" maxlength="10" readOnly style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="type" value="' + piproduct["type"] + '" maxlength="20" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="remark" value="' + piproduct["remark"] + '" maxlength="100" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="orderNo" value="' + piproduct["orderNo"] + '" maxlength="10" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="pageNo" value="' + piproduct["pageNo"] + '" maxlength="10" style="width:60px"/>';
          
         // tr.appendChild(td);
         // td = document.createElement('<td>');
         // td.innerHTML = '<input class="input" type="text" name="oldCode" value="' + piproduct["oldCode"] + '" maxlength="100" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="ecolor" value="' + piproduct["ecolor"] + '" maxlength="10" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="size" value="' + piproduct["size"] + '" maxlength="10" style="width:60px"/>';
          tr.appendChild(td);
          td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input class="input" type="text" name="col" value="' + piproduct["col"] + '" maxlength="20" style="width:60px"/>';

          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<a href="javascript:deleteRow(document.getElementById(\'' + piproduct["subSampleId"] + '\'))">删除</a>';
          tr.appendChild(td);
          table.insertBefore(tr,table.rows[table.rows.length - 1]);
        }
        
        function showDetail(productId){
        	var tr = document.getElementById(productId);
        	if(tr){
	        	if(tr.style.visibility == "visible"){
	        		tr.style.visibility = "hidden";
	        		tr.style.display = "none";
	        	}else{
	        		tr.style.visibility = "visible";
	        		tr.style.display = "";
	        	}
        	}
        }
        
        function printPiDetail(piid){
			window.open("${pageContext.request.contextPath}/pi/pidetailManager.do?method=printPi&piid=" + piid);
		}
	</script>
</head>
<body>
<center>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="30">
	<tr> 
	  <td width="22" class="page_titlebar_head">&nbsp;</td>
	  <td class="page_titlebar_bg" width="981">销售产品明细</td>
	</tr>
</table>

<table width="90%" cellspacing="0" cellpadding="0" border="0">
  <tr> 
   	<td align="right"/>
  </tr>
  <tr> 
   	<td align="right"> 
      	<input class="button_common" type="button" name="print" value="PI打印档" style="font-size:9pt" onClick="javascript:printPiDetail('<%=pidetail.getPiid()%>')"> 
    </td>
   </tr>
</table>

<table width="90%" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="100">
  <tr> 
    <td colspan="6" class="table_unfold_titlebar_small_bg">&nbsp;&nbsp;<b>合同基本信息</b></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="15%">PI编号：</td>
		<td width="17%">${pidetail.piCode}
		</td>
		 <td class="table_label" width="15%">客户编号：</td>
		<td width="17%">${pidetail.customer.customerName}
		</td>
		 <td class="table_label" width="15%">客户名称：</td>
		<td width="17%">${pidetail.customer.customerFullName}
		</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="15%">下单日期：</td>
		<td width="17%">${pidetail.piDate}
		</td>
		 <td class="table_label" width="15%">合同金额：</td>
		<td width="17%"><%=CommonUtil.format2Scale(pidetail.getTotalSum())%>
		</td>
		 <td class="table_label" width="15%">合同币种：</td>
		<td width="17%">${pidetail.coinTypeName}
		</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="15%" id="memo_TEXT">备注信息：</td>
		<td width="80%" colspan="5">${pidetail.memo}
		</td>
  </tr>
  <tr class="InputFrameLine">
  	<td width="100%" colspan="6" align="center"><input type="button" class="button_common_5" name="baseInfoButton" value="基本信息编辑" onclick="javascript:baseInfoEdit('${pidetail.piid}')"/>
  	<td>
  </tr>
</table>
<form name="piproduct" method="POST" action="${pageContext.request.contextPath}/pi/pidetailManager.do?method=modifyPiproductDetail">
<input type="hidden" name="piid" value="${pidetail.piid}"/>
<input type="hidden" name="status"/>
<table id="" width="90%" border="0" cellspacing="1" cellpadding="0" bgcolor="#999999">
	  <tbody id="piproductTbody">
      <tr bgcolor="#E7E7E7">
      	<td width="5%" align="center">详细</td>
      	<td width="5%" align="center">序号</td>
      	<td style="visibility:hidden;display:none">产品ID</td>
        <td width="10%" align="center">客户货号</td>
        <td width="10%" align="center">我司型号</td>
        <td width="10%" align="center">数量</td>
        <td width="10%" align="center">单价</td>
        <td width="10%" align="center">金额</td>
        <td width="10%" align="center">分类</td>
        <td width="10%" align="center">备注</td>
        <td style="visibility:hidden;display:none" width="5%" align="center">序号</td>
        <td width="5%" align="center">页码</td>
        <td style="visibility:hidden;display:none" width="5%" align="center">颜色描述（英）</td>
        <td style="visibility:hidden;display:none" width="5%" align="center">尺寸</td>
        <td style="visibility:hidden;display:none" width="5%" align="center">COL</td>
        <td width="5%" align="center">操作</td>
      </tr>
      <%
      	//System.out.println(storageIn.getStorageInSampleSet().size());
      	if(null != piproductList){
      		for(int i=0;i<piproductList.size();i++){
      			PiproductDetail piproductDetail = (PiproductDetail)piproductList.get(i);
      			SubSample subSample =  piproductDetail.getSubSample();
      			
      %>
      <tr id="<%=piproductDetail.getProductId()%>" bgcolor="#ffffff">
      	<td align="center"><a href="javascript:showDetail('<%=piproductDetail.getProductId()%>_DETAIL');"><font color="blue">详细</font></a></td>
      	<td align="center"><%=i+1%></td>
      	<td style="visibility:hidden;display:none"><input type="hidden" name="productId" value="<%=piproductDetail.getProductId()%>"/>
      	<input type="hidden" name="subSampleId" value="<%=subSample.getSubSampleId()%>"/>
      	<input type="hidden" name="isNew" value="<%=piproductDetail.getIsNew()%>"/></td>
      	<td><input class="input" type="text" name="custProdCode" value="<%=piproductDetail.getCustProdCode()%>" maxlength="20" style="width:60px"/></td>
        <td><%=subSample.getParentSample().getSampleCode()%></td>
        <td style="visibility:hidden;display:none"><input class="input" type="text" name="color" value="<%=piproductDetail.getColor()%>" maxlength="20" style="width:60px"/></td>
        <td><input class="input" type="text" name="prodCount" value="<%=piproductDetail.getProdCount()%>" maxlength="20" onblur="getTotalPrice(document.getElementById('<%=piproductDetail.getProductId()%>'))" style="width:60px"/></td>
        <td><input class="input" type="text" name="price" value="<%=CommonUtil.format2Scale(piproductDetail.getPrice())%>" maxlength="20" onblur="getTotalPrice(document.getElementById('<%=piproductDetail.getProductId()%>'))" style="width:60px"/><input class="input" type="text" name="priceAdd" value="<%=CommonUtil.format2Scale(piproductDetail.getPriceAdd())%>" maxlength="20" onkeyup="getTotalPrice(document.getElementById('<%=piproductDetail.getProductId()%>'))" style="width:60px"/></td>
        <td><input class="input" type="text" name="totalSum" value="<%=CommonUtil.format2Scale(piproductDetail.getTotalSum())%>" maxlength="20" readOnly style="width:60px" onblur="getTotalPrice(document.getElementById('<%=piproductDetail.getProductId()%>'))"/></td>	
        <td><input class="input" type="text" name="type" value="<%=CommonUtil.nullToStr(piproductDetail.getType())%>" maxlength="20" style="width:60px"/></td> 
        <td><input class="input" type="text" name="remark" value="<%=CommonUtil.nullToStr(piproductDetail.getRemark())%>" maxlength="100" style="width:60px"/></td>
        <td  style="visibility:hidden;display:none"><input class="input" type="text" name="orderNo" value="<%=CommonUtil.nullToStr(piproductDetail.getOrderNo())%>" maxlength="20" style="width:60px"/></td> 
        <td><input class="input" type="text" name="pageNo" value="<%=CommonUtil.nullToStr(piproductDetail.getPageNo())%>" maxlength="20" style="width:60px"/></td> 	           
        <td style="visibility:hidden;display:none"><input class="input" type="text" name="ecolor" value="<%=CommonUtil.nullToStr(piproductDetail.getEcolor())%>" maxlength="20" style="width:60px"/></td> 
        <td style="visibility:hidden;display:none"><input class="input" type="text" name="size" value="<%=CommonUtil.nullToStr(piproductDetail.getSize())%>" maxlength="20" style="width:60px"/></td> 	           
        <td style="visibility:hidden;display:none"><input class="input" type="text" name="col" value="<%=CommonUtil.nullToStr(piproductDetail.getCol())%>" maxlength="20" style="width:60px"/></td>
        <td>
        <%
  			if(null == pidetail.getState() || AppConstant.BILL_STATE_DRAWBACK ==pidetail.getState() || AppConstant.BILL_STATE_SUBMITED == pidetail.getState()){
  	  	%>
        <a href="javascript:deleteRow(document.getElementById('<%=piproductDetail.getProductId()%>'))">删除</a>
        <%}%>
        </td>
	  </tr>
	  <tr  bgcolor="#E7E7E7" id="<%=piproductDetail.getProductId()%>_DETAIL" style="visibility:hidden;display:none;">
	  	<td colspan="12">
	  		<table width="100%" bgcolor="#E7E7E7" cellspacing="0" cellpadding="0" border="0" height="100%">
	  			<tr class="InputFrameLine">
	  			<%--
	  				<td class="table_label" width="15%">客户色号：</td>
					<td width="17%"></td>
				--%>
					<td class="table_label" width="13%">旧编码：</td>
					<td width="13%"><input type="text" class="input" name="oldCode" value="<%=CommonUtil.nullToStr(piproductDetail.getOldCode())%>" maxlength="100" style="width:60px"></td>
					<td class="table_label" width="13%">颜色描述（英）：</td>
					<td width="28%"><input type="text" class="input" name="ecolor1" value="<%=CommonUtil.nullToStr(piproductDetail.getEcolor())%>"/></td>
					<td/>
  	  			</tr>
  	  			<tr class="InputFrameLine">
  	  				<td class="table_label" width="13%">印字颜色：</td>
					<td width="13%"><input type="text" class="input" name="ccolor" value="<%=CommonUtil.nullToStr(piproductDetail.getColor())%>" maxlength="100" style="width:60px"/></td>
	  				<td class="table_label" width="13%">尺寸：</td>
					<td width="28%"><input type="text" class="input" name="size1" value="<%=CommonUtil.nullToStr(piproductDetail.getSize())%>" maxlength="100" style="width:60px"/></td>
					<td class="table_label" width="13%">COL：</td>
					<td width="28%"><input type="text" class="input" name="col1" value="<%=CommonUtil.nullToStr(piproductDetail.getCol())%>" maxlength="50" style="width:60px"/></td>
  	  			</tr>
	  		</table>
	  	</td>
  	  </tr>
	  <%}}%>
	  <%
		if(null == pidetail.getState() || AppConstant.BILL_STATE_DRAWBACK ==pidetail.getState() || AppConstant.BILL_STATE_SUBMITED == pidetail.getState()){
	  %>
	  <tr bgcolor="#ffffff">
        <td colspan="12" align="center"><input type="button" name="selectNewPiproductButton" value="翻单产品查找" onclick="selectNewPiproduct('${pidetail.customer.customerId}')"/>&nbsp;
        <input type="button" name="selectNewPiproductButton" value="新产品添加" onclick="addNewPiproduct()"/>&nbsp;
        <input type="button" name="saveButton" value="保存" onclick="doSave()"/></td>
	  </tr>
	  <%}%>
	  </tbody>
</table>
</form>
<center>
${message}
</body>
</html>